package com.demo.controller.mine;

import com.demo.beans.Menu;
import com.demo.beans.Permission;
import com.demo.beans.ReturnData;
import com.demo.beans.User;
import com.demo.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("menu")
public class MenuController {
    @Autowired
    private MenuService menuService;

    /**
     * @author 文皓
     * @date 2022/7/11 17:52
     * @desc 记录菜单点击的次数、最后的点击时间、最后的点击人id
     */
    @RequestMapping("recordClick")
    public void recordClick(@RequestParam("menuAction") String menuAction, @RequestParam("userId") String userId){
        menuService.recordClick(menuAction,userId);
    }

    /**
     * @author 文皓
     * @date 2022/7/11 17:35
     * @desc 获取菜单列表
     */
    @RequestMapping("menuList")
    public ReturnData getMenuList(@RequestBody Menu menu){
        ReturnData menuList = menuService.getMenuList(menu);
        return menuList;
    }

    /**
     * @author 文皓
     * @date 2022/7/16 22:58
     * @desc 新增菜单
     */
    @RequestMapping("insertMenu")
    public ReturnData insertMenu(@RequestBody Menu menu){
        ReturnData returnData = menuService.insertMenu(menu);
        return returnData;
    }

    /**
     * @author 文皓
     * @date 2022/7/21 14:40
     * @desc 查询用户菜单权限
     */
    @RequestMapping("queryMenuPermission")
    public ReturnData queryMenuPermission(@RequestBody User user){
        ReturnData returnData = menuService.queryMenuPermission(user.getUserId());
        return returnData;
    }

    /**
     * @author 文皓
     * @date 2022/7/22 15:25
     * @desc 修改用户菜单权限
     */
    @RequestMapping("addMenuPermission")
    public ReturnData addMenuPermission(@RequestBody Permission permission){
        ReturnData returnData = menuService.addMenuPermission(permission.getUserId(), permission.getMenuId());
        return returnData;
    }

    /**
     * @author 文皓
     * @date 2022/7/27 18:02
     * @desc z
     */
    @RequestMapping("queryMenuDetail")
    public ReturnData queryMenuDetail(@RequestBody Menu menu){
        ReturnData returnData = menuService.queryMenuDetail(menu);
        return returnData;
    }

    /**
     * @author 文皓
     * @date 2022/7/27 18:27
     * @desc 更新菜单信息
     */
    @RequestMapping("updateMenu")
    public ReturnData updateMenu(@RequestBody Menu menu){
        ReturnData returnData = menuService.updateMenu(menu);
        return returnData;
    }
}
